import request from "./request.js";
import { Message } from 'element-ui';
function fetchPost(url, params) {
  var formData = new FormData();
  for (let i in params) {
    formData.append(i, params[i]);
  }
  console.log(params, "params");
  return new Promise((resolve, reject) => {
    request
      .post(url, formData)
      .then((response) => {
        if (response.code == 200) {
          console.log("正确返回", response);
          resolve(response.result);
        } else {
            console.log("失败返回", response);
            Message.error(response.string);
        }
      })
      .catch((error) => {
        Message.error(error);
        reject(error);
      });
  });
}
function fetchPost2(url, params) {
  var formData = new FormData();
  for (let i in params) {
    formData.append(i, params[i]);
  }
  console.log(params, "params");
  return new Promise((resolve, reject) => {
    request
      .post(url, formData)
      .then((response) => {
        console.log("正确返回", response);
        resolve(response);
      })
      .catch((error) => {
        console.log("错误返回");
        reject(error);
      });
  });
}

export { fetchPost, fetchPost2 };
